package day240606.thead_demo;

import day240606.thead_demo.Student;

public class StudentTest {
    public static void main(String[] args) {
        Student student=Student.STUDENT;
        Student student1=Student.STUDENT;
        System.out.println(student);
        System.out.println(student1);
        for (int i = 0; i <5 ; i++) {
            System.out.println(Student.STUDENT);

        }
    }

    public static class Student1 {
        private static Student1 instance;
        private Student1(){
            System.out.println("验证new的时候是否调用我！");
        }
        //解决方法：在public后面加一把锁synchronized
        public static Student1 getInstance() {
            if (instance == null) {
                instance = new Student1();
            }
            return instance;
        }
    }
}
